package com.bootdo.common.utils;

import cn.hutool.crypto.digest.DigestUtil;
import cn.hutool.crypto.digest.HMac;
import cn.hutool.crypto.digest.HmacAlgorithm;

/**
 * @author guoyunfei on 2021/12/28 15:41
 * @className EncryptionUtil 加密
 * @description TODO
 * @Version 1.0
 */
public class EncryptionUtil {

    private static final String SALT = "34tfcsbghop.;'guoshao@bizhi110120!#";

    private static final String SECRET_KEY = "34tf749nunbuyd56bwyw^%mery94568";


    /**
     * @return
     */
    public static String md5Encryp(String str){
        String md5Hex1 = DigestUtil.md5Hex(str + SALT);
        return md5Hex1;
    }


    /**
     * @return
     */
    public static String hmacMD5Encryp(String str){
        byte[] secret  = SECRET_KEY.getBytes();
        HMac mac = new HMac(HmacAlgorithm.HmacMD5, secret);
        String macHex1 = mac.digestHex(str);
        return macHex1;
    }

    /**
     * 多次加密
     * @param str
     * @return
     */
    public static String combinationEncryp(String str){
        String encryp = combinationEncryp(str, null);
        return encryp;
    }

    /**
     * 多次加密
     * @return
     */
    public static String combinationEncryp(String s1,String s2){
        String encryp = md5Encryp(s1 + s2);
        String hmacMD5Encryp = hmacMD5Encryp(encryp);
        return hmacMD5Encryp;
    }



    public static void main(String[] args) {
        System.out.println(combinationEncryp("123456"));
        System.out.println(combinationEncryp("18175760277","123456"));
        String pass = "c77a5ba94a9bf62b16e6b52978db3b55";
        System.out.println(combinationEncryp("12345678").equals(pass));
    }

}
